<?php
/*******************************************************************************
 *
 *  Name: Report Resolved Model
 *
 *  Date:4/1/2012
 *  
 *  Description: This model allows for access our Report_resolved table in the
 *               database.
 *  
 *  Author: David Jarman
 *  
 *  Todo:
 *     NONE
 *
 *  Modification History:  
 * 
 *   Date         Name
 *  ----------   --------------
 *  2012-04-26   DAVID JARMAN
 *  2012-04-26   DAVID JARMAN
 * 
 *****************************************************************************/
?>
<?php
class Report_resolved_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
		$this->load->database();
    }
    
    function get($ReportID)
    {
        $query = $this->db->get_where('Report_resolved', array('ReportID' => $ReportID));
        return $query->result_array();
    }

    function getAll()
    {
       $query = $this->db->get('Report_resolved');
       return $query->result_array();
    }

    function getWithIncidentID($IncidentID)
    {
        $query = $this->db->get_where('Report_resolved', array('IncidentID' => $IncidentID));
        return $query->result_array();
    }

    function getWithCustomerInfo($where = 'WHERE 1')
        {
           //$query = $this->db->query('SELECT Report.ReportID AS ReportID_save, Report.*, CustomerInfo.* FROM Report LEFT OUTER JOIN CustomerInfo ON Report.ReportID = CustomerInfo.ReportID '.$where);
           $query = $this->db->query("

           SELECT Report_resolved.ReportID AS ReportID_save, Report_resolved.*, CustomerInfo.*,
            CASE (If(( SELECT Status FROM Incident_resolved WHERE Report_resolved.IncidentID =  Incident_resolved.IncidentID) IS NULL, 0, 
            ( SELECT Status FROM Incident_resolved WHERE Report_resolved.IncidentID =  Incident_resolved.IncidentID)+1))
            WHEN 0 THEN 'Awaiting Review'
            WHEN 1 THEN 'Awaiting Assignment'
            WHEN 2 THEN 'Awaiting Repair'
            WHEN 3 THEN 'Under Repair'
            WHEN 4 THEN 'Resolved'
            END
            AS Status
            FROM Report_resolved LEFT OUTER JOIN CustomerInfo ON Report_resolved.ReportID = CustomerInfo.ReportID ".$where);

           return $query->result_array();
        }
    }
?>
